#!/bin/bash
docker --version
if [ $? -ne 0 ];then

apt-get remove docker docker-engine docker.io containerd runc
apt-get update
apt-get install \
   ca-certificates \
   curl \
   gnupg \
   lsb-release
#添加docker官网GPG密钥
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
apt-get update
apt-get install docker-ce docker-ce-cli containerd.io
echo "docker安装成功请检查 docker --version" 
else
	echo "已存在docker，请在确认一次"
	
fi

# 镜像加速器
cat /etc/docker/daemon.json
if [ $? -ne 0 ];then
	mkdir -p /etc/docker
	tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": ["https://mgft3xm2.mirror.aliyuncs.com"]
}
EOF
systemctl daemon-reload
systemctl restart docker
echo "docker 镜像加速器添加成功"
else
	echo "docker镜像加速器文件已存在或者已有镜像加速器"
	
fi
